package com.ndood.qa.dao;

import com.ndood.qa.pojo.Problem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

	/**
	 * A.2.27 根据标签ID查询出最新问题列表
	 */
	@Query("select p from Problem p where id in ( select problemid from Pl where labelid=?1 ) order by p.replytime desc ")
	public Page<Problem> findNewListByLabelId(String labelId, Pageable pageable);

	/**
	 * A.2.30 根据标签ID查询出热门问题列表
	 */
	@Query("select p from Problem p where id in ( select problemid from Pl where labelid=?1 ) order by p.reply desc ")
	public Page<Problem> findHotListByLabelId(String labelId, Pageable pageable);

	/**
	 * A.2.33 根据标签ID查询出等待回答列表
	 */
	@Query("select p from Problem p where id in ( select problemid from Pl where labelid=?1 ) and p.reply=0  order by p.createtime desc ")
	public Page<Problem> findWaitListByLabelId(String labelId, Pageable pageable);


}
